package com.roy.spring.multitenant.tenant;

public class TenantContext {
    private static final ThreadLocal<String> tenantThreadLocal = new ThreadLocal<String>();
    public static final String DEFAULT_TENANT = "public";

    public static String getTenant() {
        String tenant = tenantThreadLocal.get();
        return tenant != null ? tenant : DEFAULT_TENANT;
    }

    public static void setTenant(String tenantCode) {
        tenantThreadLocal.set(tenantCode);
    }
    
    public static void clear() {
        tenantThreadLocal.remove();
    }
}